package me.numark.activities;

import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.marshalchen.ultimaterecyclerview.ui.VerticalSwipeRefreshLayout;
import com.squareup.picasso.Picasso;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import me.numark.R;
import me.numark.fragments.AskLoginFragment;
import me.numark.fragments.BaseListFragment;
import me.numark.fragments.CommentsFragment;
import me.numark.fragments.UserGridFragment;
import me.numark.model.News;
import me.numark.model.PublishCommentResponse;
import me.numark.net.NetworkConstants;
import me.numark.net.RequestServerTask;
import me.numark.utils.Constants;
import me.numark.utils.Global;
import me.numark.utils.HttpUtil;
import me.numark.utils.Utils;

/**
 * Created by Evan on 15/7/25.
 */
public class ArticleDetailActivity extends CommentBaseActivity {

    @Bind(R.id.pic)
    public ImageView pic;

    @Bind(R.id.news_title)
    public TextView newsTitle;

    /*@Bind(R.id.mark_count)
    public TextView markCount;*/

    private News mNews;

    private BaseListFragment fragment;
    VerticalSwipeRefreshLayout swipeRefreshLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_article_detail;
        super.onCreate(savedInstanceState);
        try {
            mNews = new Gson()
                    .fromJson(getIntent().getStringExtra(Constants.NEWS_EXTRA), News.class);
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
            finish();
        }

        uiInit();
    }

    protected void uiInit() {
        fragments = new BaseListFragment[2];
        titleTextView.setText(R.string.detail_title);
        appBarLayout.setOnClickListener(this);
        if (TextUtils.isEmpty(mNews.face_img)) {
            pic.setImageResource(R.drawable.ic_feed_default_news_pic);
        } else {
            Picasso.with(this).load(mNews.face_img).into(pic);
        }
        newsTitle.setText(mNews.title);
        //markCount.setText(Integer.toString(mNews.mark_num));
        swipeRefreshLayout = (VerticalSwipeRefreshLayout)findViewById(R.id.swipe_refresh_layout);
        inputButton.setOnClickListener(this);
        switchFragment();
    }


    public void switchFragment() {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        fragment = CommentsFragment.newInstance(1, mNews.id);
        ((CommentsFragment)fragment).setRefreshLayout(swipeRefreshLayout);
        inputbar.setVisibility(View.GONE);
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
    }
}
